﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;

namespace Proggy.Web.Cms.Sections
{
    /// <summary>
    /// Section item
    /// </summary>
    public class SectionItem
    {
        /// <summary>
        /// The text to display
        /// </summary>
        public string DisplayText { get; set; }

        /// <summary>
        /// The action name
        /// </summary>
        public string ActionName { get; set; }

        /// <summary>
        /// The route values
        /// </summary>
        public object RouteValues { get; set; }

        /// <summary>
        /// The html attributes
        /// </summary>
        public object HtmlAttributes { get; set; }

        /// <summary>
        /// If true, will only use text
        /// </summary>
        public bool IsHeadingOnly { get; set; }

        /// <summary>
        /// Renders item
        /// </summary>
        /// <param name="sectionItem"></param>
        /// <returns></returns>
        public static MvcHtmlString RenderItem(SectionItem sectionItem, HtmlHelper html)
        {
            if (sectionItem.IsHeadingOnly)
            {
                return MvcHtmlString.Create(sectionItem.DisplayText);
            }
            else {
                return 
                    LinkExtensions.ActionLink(
                        html, 
                        sectionItem.DisplayText, 
                        sectionItem.ActionName, 
                        sectionItem.RouteValues, 
                        sectionItem.HtmlAttributes);
            }
        }
    }
}
